package Classes.GameViews.ViewPanels
{
	import Classes.GameDatas.GD_Character;
	import Classes.GameDatas.GD_Player;
	import Classes.GameDatas.GD_Shop;
	import Classes.GameDatas.GD_Weapon;
	import Classes.GameUtils.GU_NewThingsControler;
	import Classes.GameUtils.GU_NewThingsInfo;
	import Classes.GameUtils.GU_Sound;
	import Classes.GameUtils.MyTipSprite;
	import Classes.GameUtils.ToolTip_Sprite;
	import Classes.GameViews.GV_Map;
	import Classes.GameViews.ViewDisplayers.MapTargets.MapMoveTargets.MMT_Character;
	import Classes.GameViews.ViewScenes.VS_Main;
	import Classes.Managers.M_ConfigData;
	import Classes.staticinfo.Language;
	
	import MyComponent.MyButton;
	
	import UIComponents.FlatInfo;
	import UIComponents.IGD_ShopItem;
	import UIComponents.PanelEvent;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.system.ApplicationDomain;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	/**
	 *快速购买类 
	 * @author 邓坚
	 */
	public class VP_FastBuy_weapon extends ViewPanel
	{
		private static var _instance:VP_FastBuy_weapon;
		private var _interfaceUI:Sprite;
		private var _shopItem:IGD_ShopItem;
		public function VP_FastBuy_weapon()
		{
			init();
		}
		
		public function init():void
		{
			_interfaceUI	=  	new (ApplicationDomain.currentDomain.getDefinition("FastBuy_weaponPanel_v") as Class);
			this.addChild(_interfaceUI);
			addListener();
		}
		
		public function addListener():void
		{
			this.addEventListener(PanelEvent.CLOSE,closeFun);
			this.addEventListener("usebtn1Click",usebtn1Click);
			this.addEventListener("btnC2Click",btnC2Click);
//			this.addObserveFunc(GD_Player.instance,"QQVip",controlMoenyIcon);
			
		}
		
		private function controlMoenyIcon():void
		{

//			this._interfaceUI["controlMoenyIcon"](M_ConfigData.instance.isOpenQQVip);
		}
		
		private function usebtn1Click(e:Event):void
		{
			new GU_NewThingsControler(GU_NewThingsInfo.instance.getNewThingsByType(6));

			this.closeFun(new Event(""));
		}
		
		private function btnC2Click(e:Event):void
		{
			if(!this._shopItem.isReachMoney){		//没有足够的钱
				VP_errorPanel.instance.setErrorMessage("没有足够的钱");
				VP_errorPanel.instance.enterFrame();
				GU_Sound.instance.playCommSound("System_Prompt");
				this.closeFun(new Event(""));
				return;
			}
			
			if(this._shopItem){
				this._shopItem.sendBuyCommand();
				this.closeFun(new Event(""));
			}
			
			
		}
		
		private function closeFun(e:Event):void
		{
			GV_Map.instance.buildMode=GV_Map.CANNOTBUILDMODE;
			this.close();
		}
		
		public static function get instance():VP_FastBuy_weapon
		{
			if(!_instance) _instance=new VP_FastBuy_weapon;
			return _instance;
		}
		
		public function get interfaceUI():Sprite
		{
			return _interfaceUI;
		}
		
		public function openPanel():void
		{
			GV_Map.instance.buildMode=GV_Map.MOVEMODE;
//			setWeapon( ( GD_Player.instance.getCurrentWeaponByType( Number( GD_Player.instance.currentWeapon)) as GD_Weapon));
			setHelp();
			
			this.openAt(VS_Main.instance,true);
			this.toCenter();
		}
		
		/**
		 *设置求助，左边 
		 * 
		 */
		public function setHelp():void
		{
			setTip(this.interfaceUI["spPic1"] as DisplayObject, Language.WeaponLeftTipHelp);
		}
		
		public function setWeapon(value:GD_Weapon):void
		{
			var tipString:String	=	"";
			
			_shopItem=GD_Shop.instance.getShopInfoByItemInfo(value.itemId);
			if(_shopItem==null){
				this.closeFun(null);
				return;
			}
			this._interfaceUI["spPic2"]=_shopItem.shopItemPic;
			
			
			
			(this._interfaceUI["buyBtnRight"] as MyButton).buttonMode	 = (this._interfaceUI["btnContainerRight"] as DisplayObjectContainer).mouseEnabled 	=	this._shopItem.isReachMoney;
			
			var mtype:String="jb";
			if(this._shopItem.moneyType==0){
				if(M_ConfigData.instance.isOpenQQVip)
					mtype	=	"qb";
				else
					mtype	=	"ob";
			}
			this._interfaceUI["setMoenyIcon2"](mtype);
			this._interfaceUI["itemPrice2"]=this._shopItem.price;
			
			//热感
			tipString	=	Language.WeaponRightTipBuy;
			tipString	=	tipString.replace( "@JbType", (this._shopItem.moneyType==0?(FlatInfo.isOPenQQVip?Language.Qdian:Language.ob):Language.jb));
			tipString	=	tipString.replace( "@JbNum", this._shopItem.price);
			tipString	=	tipString.replace( "@Title", this._shopItem.itemName);
			tipString	=	tipString.replace( "@Num", this._shopItem.perNum);	
			setTip(this.interfaceUI["spPic2"] as DisplayObject, tipString);
			setTip(this.interfaceUI["btnContainerRight"] as DisplayObject, tipString);
		}
		
		/**
		 *检查子弹数量 
		 * @return 	0控制对像有子弹，1好友只有一子弹, 2玩家只有一子弹, 3好友没有子弹，4玩家没有子弹， 
		 * 
		 */
		public function check():uint		
		{
//			var targetGD:GD_Character		=	(GV_Map.instance.controlTarget as MMT_Character).gameData as GD_Character;
			var returnV:uint=0;
			if(GD_Player.instance.character.view != GV_Map.instance.controlTarget)return returnV;
			
			if((GD_Player.instance.getCurrentWeaponByType(Number(GD_Player.instance.currentWeapon)) as GD_Weapon).itemNumber <1)
			{
				returnV=4;//假设好友没子弹
				if(GD_Player.instance.character.view == GV_Map.instance.controlTarget){
					returnV=4;//玩家没子弹
					VP_FastBuy_weapon.instance.setWeapon((GD_Player.instance.getCurrentWeaponByType(Number(GD_Player.instance.currentWeapon)) as GD_Weapon));
					VP_FastBuy_weapon.instance.openPanel();
				}
			}else 
				if((GD_Player.instance.getCurrentWeaponByType(Number(GD_Player.instance.currentWeapon)) as GD_Weapon).itemNumber == 1){
					returnV=1;// 好友只有一
					if(GD_Player.instance.character.view == GV_Map.instance.controlTarget)
					returnV=2;
				}
			return returnV;
		}
		
		/**
		 *设置热感 
		 * @param d
		 * @param st
		 * 
		 */
		public function setTip(d:DisplayObject, st:String):void
		{
			ToolTip_Sprite.getInstance().removeTip(d);
			ToolTip_Sprite.getInstance().setTip(d,new MyTipSprite(st),ToolTip_Sprite.DIRECTION_LEFT);
		}
	}
}